<template>
	<view class="container">
		<view class="top">
			<text>医生注册</text>
		</view>
		<view class="login-from">
			<form @submit="formSubmit">
			  <!--用户名-->
			   <view class="inputView"> 
				<image class="nameImage" src="@/static/name.png"></image> 
				<label class="loginLab">用户名</label> 
				<input class="inputText" name="username" bindinput="usernameInput" /> 
			   </view>
			  
			  <view class="line"></view>
			  
			  <!--手机号-->
			   <view class="inputView"> 
				<image class="nameImage" src="@/static/phone.png"></image> 
				<label class="loginLab">手机号</label> 
				<input class="inputText" name="phone" bindinput="usernameInput" /> 
			   </view>		  
			 
			  <view class="line"></view>
			  
			  <!--身份证-->
			   <view class="inputView"> 
			  				<image class="nameImage" src="@/static/identity.png"></image> 
			  				<label class="loginLab">身份证号</label> 
			  				<input class="inputText" name="idCard" bindinput="usernameInput" /> 
			   </view>		  
			  			 
			  <view class="line"></view>
			  
			  <!--认证医院-->
			   <view class="inputView"> 
			  				<image class="nameImage" src="@/static/hospitalIcon.png"></image> 
			  				<label class="loginLab">认证医院</label> 
			  				<input class="inputText" name="hospital" bindinput="usernameInput" /> 
			   </view>		  
			  			 
			  <view class="line"></view>
			  
			 <!--密码-->
			 <view class="inputView"> 
			  <image class="keyImage" src="@/static/key.png"></image> 
			  <label class="loginLab">密码</label> 
			  <input class="inputText" password="true" name="password" bindinput="passwordInput" /> 
			 </view> 
			 <view class="line"></view>
			 <view class="inputView">
			  <image class="keyImage" src="@/static/key.png"></image> 
			  <label class="loginLab">确认密码</label> 
			  <input class="inputText" password="true" name="requirePassword" bindinput="passwordInput" /> 
			 </view> 
				
			  <view class="uni-btn-v">
				  <button form-type="submit">注册</button>
			  </view>
			</form>
		</view>
	</view>
	
</template>

<script>
	import { validateCell, validateIdCard, validatePassword } from '@/common/utils/validate.js'
	import{ register } from '@/api/index.js'
	export default{
		data() {
			return{
				
			}
		},
		methods:{
			formSubmit(val) {
				let param = {...val.detail.value}
				if(!param.username) {
					uni.showToast({
						title:'用户名不能为空',
						icon: 'none'
					})
				} else if (!param.hospital) {
					uni.showToast({
						title:'认证医院不能为空',
						icon: 'none'
					})
				} else {
					let cell = validateCell(param.phone)
					if(cell !== 'true') {
						uni.showToast({
							title:cell,
							icon: 'none'
						})
					} else {
						let idCard = validateIdCard(param.idCard)
						if(idCard !== 'true') {
							uni.showToast({
								title:idCard,
								icon: 'none'
							})
						} else {
							let psw = validatePassword(param.password)
							if(psw !== 'true') {
								uni.showToast({
									title:psw,
									icon: 'none'
								})
							} else {
								if(!param.requirePassword) {
									uni.showToast({
										title:'请输入确认密码',
										icon: 'none'
									})
								} else if (param.password !== param.requirePassword) {
									uni.showToast({
										title:'两次密码不正确',
										icon: 'none'
									})
								} else {
									register({...param, patient: false}).then(res =>{
										console.log(res)
										if(res.code !== 200) {
											uni.showToast({
												title:res.message,
												icon:'none'
											})
											return
										}
										console.log(res, 78)
										uni.showToast({
											title:res.message,
											icon:'none'
										})
										setTimeout(function(){
											uni.navigateBack({
												delta:1
											})
										},1000)
									})
								}
							}
						}
					}
				}
				// console.log(param)
				// console.log(validateCell(param.phone))
			},
		}
	}
</script>
<style>
	.container {
		height: 100%; 
		 display: flex; 
		 flex-direction: column; 
		 padding: 0; 
		 box-sizing: border-box; 
		/* background: linear-gradient(top, #4a8d9c, #705271); */
	}
	.top {
		padding-top: 40rpx;
		height: 20%;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: larger;
		font-weight: bold;
	}
	/*表单内容*/
		.login-from { 
		  
		 flex: auto; 
		 height:100%; 
		 padding: 60rpx;
		}
	/* 	input {
			width: 80%;
			margin-left: 100rpx;
		} */
		.inputView { 
		 /* background-color: #fff;  */
		 line-height: 45px; 
		 border-radius:20px;
		 border:1px solid #999999;
		} 
		 
		/*输入框*/
		.nameImage, .keyImage { 
		 margin-left: 20px; 
		 width: 18px; 
		 height: 16px;
		} 
		 
		.loginLab { 
		 margin: 15px 15px 15px 10px; 
		 color: #545454; 
		 font-size: 14px
		} 
		 
		.inputText { 
		 flex: block; 
		 float: right; 
		 text-align: left; 
		 margin-right: 22px; 
		 margin-top: 15px;
		 color: #cccccc; 
		 font-size: 14px
		} 
		.line { 
		 margin-top: 10px; 
		} 
		button {
		  width: 100%;
		  margin-top: 100rpx;
		  background-color: rgba(74,141,156,0.9);
		  color: white;
		  border-radius: 98rpx;
		  display: flex;
		  flex-direction: row;
		  align-items: center;
		  justify-content: center;
		}
		button::after {
		  border-radius: 98rpx;
		  border: 0; 
		}
		.uni-btn-v{
			margin-top: 50rpx;
		}
</style>

